<?php
namespace app\common\base;
use think\Controller;
use think\Db;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29
 * Time: 14:44
 */
class Comtrade extends Controller{
    /*****************机场职工+驻场职工公共方法*************************/
    /*
     * 列表查询
     * 公共方法
     * 天
     */
    public static function DayItem($table,$table_where,$where,$page=1){
        $param_page = $page;
        $param_pagesize = 10;
        $user_result  = self::DayList($table,$table_where,$where,$param_page);
        foreach ( $user_result as $key => $value){
            $user_result[$key]['Order'] = $key + 1;
        };
        //$data = self::MoneyList($user_result);
        //总条数
        $int_total_count = count($user_result);
        $data['tableData']=$user_result;
        $data['TotalCount'] = $int_total_count;
        $data['Page'] = (int)$param_page;
        $data['PageSize'] = (int)$param_pagesize;
        return $data;
    }
    /*
     * 订单查询
     */
    public static function DayList($table,$condition,$where,$param_page,$param_pagesize = 10){
        $user_result = Db::table('free_order')
            ->field(
                [
                    'COUNT(a.bus_number)'	 =>'Count',
                    'c.line_from'        =>'LineFrom',
                    'c.line_destination' =>'LineDes',
                    'b.nick_name'        =>'NickName',
                    'd.bus_number'       =>'BusNumber',
                ]
            )
            ->alias('a')
            ->join($table,$condition)
            ->join('line c','a.line_id = c.line_id','LEFT')
            ->join('bus_info d','a.deviceid = d.vehicle_device_id','LEFT')
            ->where($where)
            ->limit(($param_page - 1) * $param_pagesize, $param_pagesize)
            ->group('Money,deviceid')
            ->order('a.time desc')
            ->select();
        //echo Db::table('')->getLastSql();
        return $user_result;
    }
    /*
     * 钱数计算
     */
    public static function MoneyList($result){
        //总条数
        $int_total_count = count($result);
        $data['tableData']=$result;
        $data['TotalCount'] = $int_total_count;
        return $data;
    }
}